#include "unity.h"

#include "CircularBuffer.h"

static CircularBuffer buff;
static INT16 memoryArea[7];

void setUp()
{
	buff = CircularBuffer_Init(memoryArea+1, 5);
	memoryArea[0] = 0xDEAD;
	memoryArea[6] = 0xBEEF;
}

void tearDown()
{
	CircularBuffer_Destroy(buff);
	buff = NULL;

}

void test_CreateCircularBuffer()
{
}	

void test_AddOneItem()
{
	CircularBuffer_Add(buff,5);
	
	TEST_ASSERT_EQUAL_INT16(5, CircularBuffer_Get(buff));
}	

void test_AddDifferentItem()
{
	CircularBuffer_Add(buff,6);
	
	TEST_ASSERT_EQUAL_INT16(6, CircularBuffer_Get(buff));
}	

void test_AddTwoItems()
{
	CircularBuffer_Add(buff, 1);
	CircularBuffer_Add(buff, 2);
	
	TEST_ASSERT_EQUAL_INT16(1, CircularBuffer_Get(buff));
	TEST_ASSERT_EQUAL_INT16(2, CircularBuffer_Get(buff));
}	

void test_CircularBufferWrapsAround()
{
	CircularBuffer_Add(buff, 1);
	CircularBuffer_Add(buff, 2);
	CircularBuffer_Add(buff, 3);
	
	TEST_ASSERT_EQUAL_INT16(1, CircularBuffer_Get(buff));
	TEST_ASSERT_EQUAL_INT16(2, CircularBuffer_Get(buff));

	CircularBuffer_Add(buff, 4);
	CircularBuffer_Add(buff, 5);
	CircularBuffer_Add(buff, 6);
	
	TEST_ASSERT_EQUAL_INT16(3, CircularBuffer_Get(buff));
	TEST_ASSERT_EQUAL_INT16(4, CircularBuffer_Get(buff));
	TEST_ASSERT_EQUAL_INT16(5, CircularBuffer_Get(buff));
	TEST_ASSERT_EQUAL_INT16(6, CircularBuffer_Get(buff));
	TEST_ASSERT_EQUAL_HEX16(0xDEAD, memoryArea[0]);
	TEST_ASSERT_EQUAL_HEX16(0xBEEF, memoryArea[6]);
}
